/*
    Document   : mostrarUsuario
    Created on : 20/05/2013, 12:47:11 AM
    Author     : vyamunaque
*/
package dao.basedato;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author vyamunaque
 */
public class Conexion {
    private Connection con = null;
    
    public static String url = "jdbc:derby://localhost:1527/transportes";
    public static String dbdriver = "org.apache.derby.jdbc.ClientDriver";
    public static String username = "alumnoUPC";
    public static String password = "201300688";  
    
    public Conexion() throws Exception {
        try {
           /*
            Context initCtx = new InitialContext();
            Context envCtx = (Context) initCtx.lookup("java:comp/env");
            DataSource ds = (DataSource) envCtx.lookup("jdbc/BookDB");
            con = ds.getConnection();
             */
            Class.forName(dbdriver);
            con = DriverManager.getConnection(url, username, password);
            
        } catch (Exception ex) {
            throw new Exception("No pudo conectarse a base de datos: " +
                    ex.getMessage());
        }
    }

    public Connection getConexion(){
        return con;
    }
     public void cerrarConexion() {
        try {
            con.close();
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        }
    }
    

}

